#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/9/23 18:47
# @Author  : AshJo
# @Desc    : 抽象类的实现
# @Filename: abstract_class.py
# @Version : v1.0
"""

# 模拟各个平台的支付程序接口实现

"""基于调用abc模块实现的抽象类，约束性更强"""


# from abc import ABCMeta, abstractmethod

# class Payment(metaclass=ABCMeta):
#     @abstractmethod
#     def pay(self, money):
#         raise NotImplementedError('请在子类中重写同名pay方法')

class Payment:
    def pay(self, money):
        raise NotImplementedError('请在子类中重写同名pay方法')


class Alipay(Payment):
    def __init__(self, name):
        self.name = name

    def pay(self, money):
        dic = {'username': self.name, 'price': money}
        # 想办法调用支付宝的支付接口 url连接 把dic传过去
        print('%s用户通过支付宝支付了%s元' % (self.name, money))


class WeChat(Payment):
    def __init__(self, name):
        self.name = name

    def pay(self, money):
        dic = {'username': self.name, 'price': money}
        # 想办法调用微信支付接口 url连接 把dic传过去
        print('%s用户通过微信支付了%s元' % (self.name, money))


def pay(name, money, kind):
    if kind == 'Alipay':
        obj = Alipay(name)
    elif kind == 'WeChat':
        obj = WeChat(name)
    obj.pay(money)


pay('alex', 888, 'Alipay')
pay('alex', 998, 'WeChat')
